const http = require('http')
const fs = require('fs')

var root= (__dirname,'./dist'); //你本地放index.html页面的文件路径

const serve = http.createServer((req,res) => {
    var url = req.url;
    var file = root+url;
    fs.readFile(file,function(err,data){
        if(err){
            res.writeHeader(404,{
                'content-type' : 'text/html;charset="utf-8"'
            });
            res.write('<h1>404错误</h1><p>你要找的页面不存在</p>');
            res.end();
        }else{
            res.writeHeader(200,{
              //  'content-type' : 'text/html;charset="utf-8"'
            });
            res.write(data);//将index.html显示在客户端
            res.end();
        }
    })

})
serve.listen(2000)
console.log('listen')